package com.tianda.his.modules.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tianda.his.commons.utils.LoginUtils;
import com.tianda.his.commons.vo.AjaxResult;
import com.tianda.his.modules.system.dto.LoginDto;
import com.tianda.his.modules.system.dto.UserDto;
import com.tianda.his.modules.system.entity.SysDept;
import com.tianda.his.modules.system.entity.SysUser;
import com.tianda.his.modules.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.time.LocalDateTime;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author jinken
 * @since 2025-09-12
 */
@RestController
@RequestMapping
public class SysUserController {

    @Autowired
    protected ISysUserService sysUserService;

    /**
     * 分页查询
     * @param userDto
     * @return
     */
    @GetMapping("/system/user/listUserForPage")
    public AjaxResult listUserForPage(UserDto userDto) {

        Page<SysUser> pageResult = sysUserService.listDeptForPage(userDto);
        return AjaxResult.success(pageResult.getRecords(), pageResult.getTotal());
    }

    /**
     * 新增用户
     * @param sysUser
     * @return
     */
    @PostMapping("/system/user/addUser")
    public AjaxResult addUser(@Validated SysUser sysUser) {
        sysUser.setCreateBy(LoginUtils.getLoginUser().getUserName());
        sysUser.setCreateTime(LocalDateTime.now());
        sysUserService.save(sysUser);
        return AjaxResult.success();
    }


}
